<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="javax.*,java.sql.*,com.dao.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>注册提交</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>


	<body>
		<%
			String name = "lfr";
			String password = "lfr";
			String driver = "oracle.jdbc.driver.OracleDriver";
			String url = "jdbc:oracle:thin:@127.0.0.1:1521:jssbook";

			int result = 0;

			Class.forName(driver);

			Connection conn = DriverManager.getConnection(url, name, password);// 2

			String sql = "insert into usersinfo(user_id,user_name,user_password,user_gender,user_interest,user_address) values(seq.nextval,?,?,?,?,?)";

			PreparedStatement prestmt = conn.prepareStatement(sql);// 3

			request.setCharacterEncoding("utf-8");// 设定传入参数编码

			prestmt.setString(1, request.getParameter("name"));
			prestmt.setString(2, request.getParameter("password"));
			prestmt.setString(3, request.getParameter("gender"));

			String interest[] = request.getParameterValues("interest");
			String interestcontent = "";
			if (interest != null) {
				for (int i = 0; i < interest.length; i++) {
					interestcontent = interestcontent + "、" + interest[i];
				}
			}
			prestmt.setString(4, interestcontent);

			prestmt.setString(5, request.getParameter("city"));

			result = prestmt.executeUpdate();// 4

			if (result == 0) {
		%>
		提交失败！
		<a href="zhuce.jsp">重新提交</a>
		<%
			} else if (result == 1) {
		%>

		注册成功！
		<a href="homepage.jsp">回到主页</a>
		<%
			}

			out.flush();
			out.close();
		%>
		<%--
			UserDao userdao = new UserDao();
			Userinfo userinfo = new Userinfo();
			userinfo.setName(request.getParameter("name"));
			userinfo.setPassword(request.getParameter("password"));
			userinfo.setPassword(request.getParameter("gender"));
			String interest[] = request.getParameterValues("interest");
			String interestcontent = "";
			if (interest!= null)
				for (int i = 1; i < interest.length; i++) {
					interestcontent = interestcontent + "," + interest[i];
				}

			userinfo.setPassword(request.getParameter("interestcontent"));
			userinfo.setPassword(request.getParameter("city"));
			userdao.save(userinfo);
		--%>


	</body>
</html>
